using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.SupplyChain.Material;


namespace HengTong.ViewModel.SupplyChain.SysMaterialAttributeValueVms
{
    public partial class SysMaterialAttributeValueListVm : BaseListVm<SysMaterialAttributeValueView, SysMaterialAttributeValueSearcher>
    {

        protected override IEnumerable<IGridColumn<SysMaterialAttributeValueView>> InitGridHeader()
        {
            return new List<GridColumn<SysMaterialAttributeValueView>>{
                this.MakeGridHeader(x => x.AttributeName),
                this.MakeGridHeader(x => x.Value),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysMaterialAttributeValueView> GetSearchQuery()
        {
            var query = DC.Set<SysMaterialAttributeValue>()
                .CheckEqual(Searcher.AttributeId, x=>x.AttributeId)
                .CheckContain(Searcher.Value, x=>x.Value)
                .Select(x => new SysMaterialAttributeValueView
                {
				    ID = x.ID,
                    AttributeName = x.Attribute.Name,
                    Value = x.Value,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }

    public class SysMaterialAttributeValueView : SysMaterialAttributeValue{
        [Display(Name = "属性名称")]
        public String AttributeName { get; set; }

    }
}
